package com.garen.fire.web;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.garen.common.BaseAction;
import com.garen.common.MsgBean;
import com.garen.common.PageBean;
import com.garen.fire.biz.IFireCarBiz;
import com.garen.fire.biz.IFireCaseInfoBiz;
import com.garen.fire.entity.FireCar;
import com.garen.sys.filter.SysFilter;


@Controller
@RequestMapping("/fire")
public final class FireCarAction extends BaseAction{

	@Autowired
	private IFireCarBiz iFireCarBiz;

	@Autowired
	private IFireCaseInfoBiz iFireCaseInfoBiz;

	//查询单车信息
	@RequestMapping("/firecar/get") 
	public ModelAndView json(FireCar fireCar) {
		MsgBean mbean = SysFilter.getMsgBean();
		if(fireCar.getCarId() == null) {
			mbean.setRetInfo(-1, "参数不能为空!");
		}else {
			mbean.setObj(iFireCarBiz.getFireCar(fireCar));
		}
		return Json(mbean);
	}
	
	/*
	 * 获取案情相关资源
	 * 		派遣车辆信息
	 * 	    录音是否存在
	 * */
	@RequestMapping("/firecar/getres") 
	public ModelAndView sendCar(String ajbh) {
		MsgBean mbean = SysFilter.getMsgBean();
		if(StringUtils.isEmpty(ajbh)) {
			mbean.setRetInfo(-1, "参数不能为空!");
		}else {
			JSONObject json = new JSONObject();
			json.put("carlist", iFireCarBiz.getSendFireCar(ajbh));
			mbean.setObj(json);
		}
		return Json(mbean);
	}
	
	@RequestMapping("/firecar/json") 
	public ModelAndView json(PageBean<FireCar> pb,FireCar fireCar) {
		iFireCarBiz.getFireCarList(pb,fireCar);
		return Json(pb);
	}

	@RequestMapping("/firecar/boxJson") 
	public ModelAndView boxJson(FireCar fireCar) {
		return Json(iFireCarBiz.getFireCarList(fireCar));
	}

	@RequestMapping("/firecar/edit") 
	public ModelAndView edit(ModelAndView mav,FireCar fireCar) {
		mav.setViewName("fire/FireCarEdit");
		if(fireCar.getCarId() != null){
			fireCar=iFireCarBiz.getFireCar(fireCar);
		}
		mav.addObject("fireCar",fireCar);
		return mav;
	}

	@RequestMapping("/firecar/save") 
	public ModelAndView save(FireCar fireCar) {
		MsgBean mbean = SysFilter.getMsgBean(0, "保存成功 !");
		iFireCarBiz.saveFireCar(mbean,fireCar);
		return Json(mbean);
	}

	@RequestMapping("/firecar/del") 
	public ModelAndView del(FireCar fireCar) {
		MsgBean mbean = SysFilter.getMsgBean(0, "删除成功 !");
		iFireCarBiz.delFireCar(mbean,fireCar);
		return Json(mbean);
	}
	 
	@RequestMapping("/firecar/getcarcount")
	public ModelAndView getcarcount(String org_id) {
		MsgBean mbean = SysFilter.getMsgBean();
		if (org_id == null) {
			mbean.setRetInfo(-1, "参数不能为空!");
			return Json(mbean);
		}
		mbean.setObj(iFireCarBiz.getcarcount(org_id));
		return Json(mbean);
	}
}
